package cn.mason.echarts.service;

import com.baomidou.kisso.SSOHelper;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;


@Service
public class FileService {
    @Autowired
    RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "uploadError")
    public String upload(FileSystemResource file ,String filepath) {
        MultiValueMap param=new LinkedMultiValueMap();
        param.add("file",file);
        param.add("filepath",filepath);
        ResponseEntity<String> responseEntity=restTemplate.postForEntity("http://SERVICE-FILE/uploadFile",param,String.class);
        return responseEntity.getBody();
    }

    public String uploadError(String name) {
        return "File service error";
    }
}
